#include < bits / stdc++.h>
usingnamespacestd;

constintN = 205;

intn, dp[N][N];
charma[N][N];

queue<pair<int, int>> q;
intmain()
{
    cin >> n;
    // 读取字符数组ma[i][j]表示：i到j之间的字符
    for (inti = 1; i <= n; i++)
    {
        for (intj = 1; j <= n; j++)
            cin >> ma[i][j];
    }
    // dp数组全部初始为-1，即未被访问过
    memset(dp, -1, sizeof(dp));
    // 自己到自己为空字符，长度为0
    for (inti = 1; i <= n; i++)
        dp[i][i] = 0, q.push({i, i});
    // i到j有路，则为单个字符的回文，长度为1
    for (inti = 1; i <= n; i++)
        for (intj = 1; j <= n; j++)
            if (ma[i][j] != '-')
                if (i != j)
                    dp[i][j] = 1, q.push({i, j});
    // bfs一般写法
    while (!q.empty())

    {
        intu = q.front().first;  // 起点
        intv = q.front().second; // 终点
        q.pop();                 // 删除头
        for (inti = 1; i <= n; i++)
            for (intj = 1; j <= n; j++)
            {
                //{u,v}本身是最短回文，在这基础上扩展
                // 要使得{i,u,v,j}仍然是回文
                // 要保证ma[i][u]==ma[v][j],并且连通即ma[i][u]!='-'
                // bfs最短路特性，保证了最先更新的就是最短的,dp[i][j]>-1表示更新过了
                if (ma[i][u] != ma[v][j] || ma[i][u] == '-' || dp[i][j] > -1)
                    continue;
                dp[i][j] = dp[u][v] + 2;
                q.push(make_pair(i, j));
            }
    }

    for (inti = 1; i <= n; i++)
    {
        for (intj = 1; j <= n; j++)
            cout << dp[i][j] << "";
        cout << endl;
    }
}